package com.itheima.mapper;

import com.itheima.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author panweiwei
 */
@Mapper
public interface UserMapper {
    /**
     * @param username 用户名
     * @return 用户实体类
     */
    @Select("select * from user where username = #{username}")
    User findByUserName(String username);

    /**
     * 用户注册
     *
     * @param username  用户名
     * @param md5String 密码
     * @return
     */
    @Insert("insert into user (username, password, create_time, update_time)" +
            "values (#{username},#{md5String},now(),now())")
    Boolean addUser(String username, String md5String);

    /**
     * 更新用户信息
     *
     * @param user
     * @return
     */
    @Update("update user set username = #{username} ,nickname = #{nickname}, email = #{email}, user_pic = #{userPic}, update_time = #{updateTime} where id = #{id}")
    Boolean upDate(User user);

    /**
     * 更新用户头像
     *
     * @param avatarUrl 头像地址
     * @param id        用户id
     */
    @Update("update user set user_pic = #{avatarUrl} ,update_time = now() where id = #{id}")
    void updateAvatar(String avatarUrl, Integer id);

    /**
     * 更新密码
     *
     * @param md5String
     * @param id
     */
    @Update("update user set password = #{md5String} ,update_time = now() where id = #{id}")
    void updatePwd(String md5String, Integer id);
}
